export class UserData{
    coin:number;
    nick:string;
    level:number;
    avatar:string;

    userId:string;
    public static instance:UserData;
    constructor(){
        this.coin = 0;
        this.nick = "我";
        this.level = 1;
        this.avatar = "";
        this.userId = "";
        UserData.instance = this;
    }

    setUinfo(data):void{
        this.avatar = data.avatarUrl||'';
        this.nick = data.nickName||'我';
    }

    save():void{
        Laya.LocalStorage.setJSON('userdata',this);
    }

}

export function loadUserData():UserData{
   let udata = new UserData();

   let data = Laya.LocalStorage.getJSON("userdata");
   if(data){
       for(let attr in data){
           udata[attr] = data[attr];
       };
   }
   return udata;
}
